import { _decorator, Component, Node, PhysicsSystem2D, Graphics, Tween, Vec2, tween, Vec3, Quat, color, Color, Sprite, repeat, AnimationState } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('NewComponent')
export class NewComponent extends Component {
	start() {
		let quat: Quat = new Quat();
		Quat.fromEuler(quat, 180, 0, 0);

		class BindTarget {
			color: Color
		}

		let sprite: Sprite = this.node.getComponent(Sprite);
		let bindTarget: BindTarget = new BindTarget();
		bindTarget.color = Color.RED;
		// 链式执行
		let move = tween(this.node.getPosition())
			.to(10, new Vec2(0, 10), {
				onUpdate: (target: Vec3, ratio: number) => {
					this.node.setPosition(target)
				}
			})
			.to(10, new Vec3(3, 3, 1), {
				onUpdate: (target: Vec3, ratio: number) => {
					this.node.setScale(target)
				}
			})
		// 并行
		let move2 = tween().target(this.node)
			.to(2,
				{
					position: new Vec3(0, 10, 0),
					scale: new Vec3(3, 3, 1),
					rotation: quat,
				}
			)
		let color = tween(bindTarget)
			.to(0.1, { color: Color.RED }, {
				onUpdate(tar: BindTarget) {
					sprite.color = tar.color;
				}
			})
		setTimeout(() => {
			move2.start()
			color.start()
		}, 1000)
	}

	update(deltaTime: number) {

	}
}

